""" category模型 """

from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import relationship

from database.database import Base


class Category(Base):
    __tablename__ = "category"

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    name = Column(String, unique=True, nullable=False, index=True)

    articles = relationship("Article", back_populates="category")

    def to_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
